import request from '@/utils/request';
import { AxiosPromise } from 'axios';

export interface TagInfoVO {
  category_name: string;
  category_id?: number;
  categories: TagInfoVO[];
}

export interface MicroAppQuery extends PageQuery {
  accountId: number;
  advertiserId: number;
  searchKey?: string;
}

export interface ByteMicroAppVO {
  pageInfo: {
    page: number;
    pageSize: number;
    totalNumber: number;
    totalPage: 1;
  };
  list: ByteMicroAppItem[];
}

export interface ByteMicroAppItem {
  advertiserId: number;
  appId: string;
  auditStatus: string;
  createTime: string;
  discountRate: string;
  hasDiscount: boolean;
  hasOnlineEarning: boolean;
  instanceId: string;
  maxPaymentTierRange: string;
  maxRechargeTier: string;
  membershipType: string;
  midPaymentTierRange: string;
  minPaymentTierRange: string;
  minRechargeTier: string;
  modifyTime: string;
  name: string;
  paymentForm: string;
  propName: string;
  reason: string;
  recommendedRechargeTier: string;
  remark: string;
  revenueModel: null;
  tagInfo: string;
}

export interface WechatMicroAppVO {
  total: number;
  rows: WechatMircroAppItem[];
  sum: [
    {
      type: string;
      desc: string;
      flag: boolean;
    }
  ];
}

export interface WechatMircroAppItem {
  advertiserId?: number | null;
  auditStatus?: string;
  createTime?: null | string;
  discountRate?: number | null;
  guideText?: null | string;
  hasDiscount?: boolean | null;
  hasOnlineEarning?: boolean | null;
  headerImageUrl?: null | string;
  iconImageUrl?: null | string;
  imagesHorizontalUrl?: string[] | null;
  imagesVerticalUrl?: string[] | null;
  instanceId?: number | null;
  introduction?: null | string;
  labels?: string[] | null;
  maxPaymentTierRange?: string;
  maxRechargeTier?: string;
  membershipType?: string;
  midPaymentTierRange?: string;
  minPaymentTierRange?: string;
  minRechargeTier?: string;
  modifyTime?: null | string;
  name?: null | string;
  path?: null | string;
  paymentForm?: string;
  propName?: null | string;
  reason?: null | string;
  recommendedRechargeTier?: string;
  remarkMessage?: null | string;
  revenueModel?: string;
  tagInfo?: null | string;
  userName?: null | string;
  [property: string]: any;
}

/**
 * APP :APP
DPA :DPA
LINK :LINK
MICRO_GAME :MICRO_GAME
NATIVE_ACTION :NATIVE_ACTION
QUICK_APP :QUICK_APP
SHOP :SHOP
 */
export type LandingType = 'APP' | 'DPA' | 'LINK' | 'MICRO_GAME' | 'NATIVE_ACTION' | 'QUICK_APP' | 'SHOP';
/**
 * 广告类型 ALL 信息流
    ALL :ALL
*/
export type AdType = 'ALL' | 'SEARCH';
/**
 * APP应用
AWEME抖音主页
ENTERPRISE企业号落地页
MICRO_APP字节小程序
ORANGE橙子落地页
QUICK_APP快应用
THIRDPARTY自研落地页
WECHAT_APP微信小程序
*/
export type AssetType = 'APP' | 'AWEME' | 'ENTERPRISE' | 'MICRO_APP' | 'MINI_PROGRAM' | 'ORANGE' | 'QUICK_APP' | 'THIRDPARTY' | 'WECHAT_APP';
/**
 * MANUAL 手动投放模式
PROCEDURAL 自动投放模式
*/
export type deliveryMode = 'MANUAL' | 'PROCEDURAL';

/**
 *是否设置差异价值，可选值: 
DISABLED 未设置
DISCRIMINATEBYGROUP 人群差异价值
DYNAMICVALUE 动态价值
FIXED 固定价值
*/
export type ValueType = 'DISABLED' | 'DISCRIMINATEBYGROUP' | 'DYNAMICVALUE' | 'FIXED';

export interface ManagerOptimizedGoalQuery extends PageQuery {
  accountId: number;
  advertiserId?: number;
  landingType: LandingType;
  adType?: AdType;
  assetType?: AssetType;
  deliveryMode?: deliveryMode;
  miniProgramId?: string;
  microAppInstanceId?: string;
}

export interface EventManagerDeepBidTypeQuery extends PageQuery {
  accountId: number;
  advertiserId?: number;
  externalAction?: string;
}

export interface ManagerOptimizedGoalData {
  assetIds: any;
  goals: ManagerOptimizedGoalVO[];
}

export interface ManagerOptimizedGoalVO {
  assetTypes?: AssetType[];
  deepGoals?: any;
  externalAction: string; //优化目标
  historyBack?: boolean; //历史有无回传, TRUE 表示有，FALSE 表示无
  optimizationName: string; //事件名称
  twentyFourHourBack?: boolean; //24 小时历史有无回传, TRUE 表示有，FALSE 表示无
  valueType?: ValueType;
}

export interface TagInfoQuery extends PageQuery {
  type: 1 | 2; //1-字节小程序；2-微信小程序；
}

export type SubDistrictType = 'ONE_LEVEL' | 'TWO_LEVEL' | 'THREE_LEVEL' | 'FOUR_LEVEL' | 'NONE';

export interface AddressQuery {
  accountId: number;
  advertiserId?: number;
  externalAction?: string;
  codes?: string[];
  language?: 'CN' | 'CN_GOV';
  subDistrict: SubDistrictType;
}

export const listTagInfo = (query: TagInfoQuery): AxiosPromise<TagInfoVO> => {
  return request({
    url: '/oce/third/getTagInfo',
    method: 'get',
    params: query
  });
};
/**
 * 获取字节小程序
 */
export const byteMircroAppList = (query: MicroAppQuery): AxiosPromise<ByteMicroAppVO> => {
  return request({
    url: '/oce/third/queryToolsMicroApp',
    method: 'get',
    params: query
  });
};

/**
 * 获取字节小程序-添加资产时选择字节小程序
 */
export const queryToolsMicroAppNew = (query: MicroAppQuery): AxiosPromise<ByteMicroAppItem[]> => {
  return request({
    url: '/oce/third/queryToolsMicroAppNew',
    method: 'get',
    params: query
  });
};

/**
 * 获取微信小程序
 */
export const wechatMircroAppList = (query: MicroAppQuery): AxiosPromise<WechatMircroAppItem[]> => {
  return request({
    url: '/oce/third/queryWechatApplet',
    method: 'get',
    params: query
  });
};

/**
 * 查询微信创建/共享的小程序
 */
export const getAllWechatApplet = (query: MicroAppQuery): AxiosPromise<WechatMircroAppItem[]> => {
  return request({
    url: '/oce/third/getAllWechatApplet',
    method: 'get',
    params: query
  });
};

/**
 * 获取可用优化目标（巨量广告升级版）
 */
export const getEventManagerOptimizedGoal = (query: ManagerOptimizedGoalQuery): AxiosPromise<ManagerOptimizedGoalData> => {
  return request({
    url: '/oce/third/getEventManagerOptimizedGoal',
    method: 'get',
    params: query
  });
};

/**
 * 获取可用优化目标（巨量广告升级版）
 */
export const getEventManagerDeepBidType = (query: EventManagerDeepBidTypeQuery): AxiosPromise<ManagerOptimizedGoalData> => {
  return request({
    url: '/oce/third/getEventManagerDeepBidType',
    method: 'get',
    params: query
  });
};

/**
 * 获取行政信息
 */
export const getAddressListInfo = (query: AddressQuery): AxiosPromise<any> => {
  return request({
    url: '/oce/third/getAdminInfo',
    method: 'get',
    params: query
  });
};
